package com.yuxl.common.auth.repository;

import com.yuxl.common.auth.entity.AuthMenu;
import com.yuxl.common.auth.entity.AuthPermission;
import com.yuxl.common.auth.entity.AuthRoleMenu;
import com.yuxl.common.auth.entity.AuthUser;
import com.yuxl.common.core.annotation.PostgreSqlRepository;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import com.yuxl.common.core.annotation.PostgreSqlRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @Author : yuxl
 * @create 2025/7/23 上午11:18
 */
@PostgreSqlRepository
public interface AuthRoleMenuRepository extends ReactiveCrudRepository<AuthRoleMenu, String> {
    @Query("""
            SELECT m.name
            FROM auth_menu m
            INNER JOIN auth_role_menu rm ON m.name = rm.menu_name
            WHERE rm.role_mark = :roleMark
            """)
    Flux<AuthMenu> findByRoleMark(String roleMark);

    @Query("""
            SELECT m.name
            FROM auth_menu m
            INNER JOIN auth_role_menu rm ON m.name = rm.menu_name
            WHERE rm.role_mark in (:roleMarks)
            """)
    Flux<AuthMenu> findByRoleMarks(List<String> roleMarks);

    @Query("""
            DELETE FROM auth_role_menu WHERE role_mark = :roleMark
            """)
    Mono<Long> deleteByRoleMark(String roleMark);
}
